﻿using System;
using System.Collections.Generic;
using System.Text;
using micsun.Logic;
using System.Data;
using micsun.Data;
using micsun.SqlDom;

namespace commfuncs.RPT
{
    public class RptMananger
    {
        /// <summary>
        /// 
        /// </summary>
        public RptMananger(string ReportName)
        {
            _reportName = ReportName;
            _reportTable = getReportTable();
            getReportTitle();
        }
        private string _reportName;
        private DataTable _reportTable;
        private string _reportTitle;

        /// <summary>
        /// 报表相关的参数表
        /// </summary>
        public DataTable ReportTable
        {
            get { return _reportTable; }
        }
        /// <summary>
        /// 报表的显示名称
        /// </summary>
        public string ReportTitle
        {
            get { return _reportTitle; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ReportName"></param>
        /// <returns></returns>
        private DataTable getReportTable()
        {

            SqlParameterDeclaration pKeyID = new SqlParameterDeclaration("ReportName");
            string sql = "select * from RPTBASE where 报表名称=" + pKeyID.Generate() + " order by 是否显示,显示次序";
            DataParameterCollection parameters = new DataParameterCollection();
            parameters.Add(DbParameterFactory.DefaultFactory.CreateParameter("ReportName", DbType.AnsiString));
            parameters[0].Value = _reportName;
            DataTable dt = new DataTable();
            micsunDB.CreateDataAdapter(sql, parameters).Fill(dt);
            return dt;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ReportName"></param>
        /// <returns></returns>
        private void getReportTitle()
        {
            if (this._reportTable.Rows.Count>0)
            {
                if (_reportTable.Rows[0]["报表说明"] != DBNull.Value)
                {
                    _reportTitle = _reportTable.Rows[0]["报表说明"].ToString();
                }
                else
                {
                    _reportTitle = string.Empty;
                }
            }
        }
    }
}
